# encoding=utf-8
# author:梁子龙
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer


class MyTokenObtainPairSerializer(TokenObtainPairSerializer):
    """
    自定义令牌
    """

    @classmethod
    def get_token(cls, user):
        token = super(MyTokenObtainPairSerializer, cls).get_token(user)

        # Add custom claims
        token['logo'] = '爱谌的缘'
        return token

    def validate(self, attrs):
        """
        自定义返回的格式
        """
        old_data = super().validate(attrs)

        # refresh = self.get_token(self.user)
        data = {'status': 1004,
                'msg': '成功',
                "token": old_data,
                # 'refresh': str(refresh),
                # 'access': str(refresh.access_token)
                }

        return data


from rest_framework_simplejwt.serializers import TokenObtainPairSerializer


# class MyTokenObtainPairSerializer(TokenObtainPairSerializer):
#
#     '''
#     token验证
#     '''
#     def validate(self, attrs):
#         data = super().validate(attrs)
#
#         refresh = self.get_token(self.user)
#
#         data['refresh'] = str(refresh)
#         data['access'] = str(refresh.access_token)
#         data['username'] = self.user.username #这个是你的自定义返回的
#         data['user_id'] = self.user.id #这个是你的自定义返回的
#
#         return data

